package Service.Impl;

import Dao.CourseContentMapper;
import Service.CourseContentService;
import domain.Course;
import domain.CourseSection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Date;
import java.util.List;

@Service
public class CourseContentServiceImpl implements CourseContentService {

    @Autowired
    private CourseContentMapper courseContentMapper;

    @Override
    public List<CourseSection> findSectionAndLessonByCourseID(int courseid) {

        List<CourseSection> list = courseContentMapper.findSectionAndLessonByCourseID(courseid);

        return list;
    }

    @Override
    public Course findCourseById(int courseid) {

        Course course = courseContentMapper.findCourseById(courseid);
        return course;
    }

    /*
        添加章节信息
     */
    @Override
    public void saveOrUpdateSection( CourseSection courseSection) {

        Date date = new Date();
        courseSection.setCreateTime(date);
        courseSection.setUpdateTime(date);

        courseContentMapper.saveOrUpdateSection(courseSection);
    }


    /*
          更新 章节信息
     */
    @Override
    public void updateSection(CourseSection courseSection) {

        //1. 补全信息
        courseSection.setUpdateTime(new Date());


        //2. 调用Dao方法

        courseContentMapper.updateSection(courseSection);

    }

    @Override
    public void updateSectionStatus(int id, int status) {

        //1.封装数据
        CourseSection courseSection = new CourseSection();
        courseSection.setStatus(status);
        courseSection.setUpdateTime(new Date());
        courseSection.setId(id);

        //2.调用Dao
        courseContentMapper.updateSectionStatus(courseSection);

    }
}
